<?php 
require_once (dirname(__FILE__)."/services.php");
class people_RouterExtension extends Extension {
    public function apply(&$context, Chain $chain) {
        $context['rule']['{^/people/*$}'] = dirname(__FILE__)."/actions.php";
		$context['rule']['{^/people/(\w+)/}'] = dirname(__FILE__)."/actions.php";

        $chain->next($context);
    }
}

class peopleFeature extends Feature {
    public function registerExtension() {
        $this->extensions = Array( 
              	 new people_RouterExtension("com.yizin.platform.router")
		);
    }
    
    public function registerExtendable() {
    }
    
    public function init() {
    	$conn = getDBConnection();
		$conn->query('drop table if exists people;');
		$conn->query('drop table if exists people_profiles;');
		
		$query_people = 'CREATE TABLE people (
			id_person BIGINT PRIMARY KEY AUTO_INCREMENT,
			first_name VARCHAR(255) NOT NULL,
			last_name VARCHAR(255) NOT NULL,
			gender VARCHAR(20) NOT NULL,
			mail VARCHAR(255) NOT NULL,
			photo VARCHAR(255) NULL,
			title VARCHAR(255) NOT NULL,
			enrolled_date VARCHAR(255) NULL,
			catagory VARCHAR(255) NOT NULL
		)CHARSET=utf8;';
		
		$query_people_profiles = 'CREATE TABLE people_profiles(
			id BIGINT PRIMARY KEY AUTO_INCREMENT,
			id_person BIGINT NOT NULL,
			profile_key VARCHAR(255) NOT NULL,
			profile_value TEXT NULL
		)CHARSET=utf8;';
		
    	$conn->query($query_people);
		$conn->query($query_people_profiles);
		
		$conn->disconnect();
	}
    
    public function destroy() {
    	$conn=getDBConnection();
		
		$conn->query('drop table if exists people;');
		$conn->query('drop table if exists people_profiles;');
		
		$conn->disconnect();
    }
}

$featureClass = "peopleFeature";
$featureName = "People";
$featureIntroduction = "people feature";
?>
